<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>helloworlddialog.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_demos_editor_helloworlddialog.js.html">helloworlddialog.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2008 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview An example of how to write a dialog to be opened by a plugin.
<a name="line17"></a> *
<a name="line18"></a> */
<a name="line19"></a>
<a name="line20"></a>goog.provide(&#39;goog.demos.editor.HelloWorldDialog&#39;);
<a name="line21"></a>goog.provide(&#39;goog.demos.editor.HelloWorldDialog.OkEvent&#39;);
<a name="line22"></a>
<a name="line23"></a>goog.require(&#39;goog.dom.TagName&#39;);
<a name="line24"></a>goog.require(&#39;goog.events.Event&#39;);
<a name="line25"></a>goog.require(&#39;goog.string&#39;);
<a name="line26"></a>goog.require(&#39;goog.ui.editor.AbstractDialog&#39;);
<a name="line27"></a>
<a name="line28"></a>
<a name="line29"></a>// *** Public interface ***************************************************** //
<a name="line30"></a>
<a name="line31"></a>
<a name="line32"></a>
<a name="line33"></a>/**
<a name="line34"></a> * Creates a dialog to let the user enter a customized hello world message.
<a name="line35"></a> * @param {goog.dom.DomHelper} domHelper DomHelper to be used to create the
<a name="line36"></a> * dialog&#39;s dom structure.
<a name="line37"></a> * @constructor
<a name="line38"></a> * @extends {goog.ui.editor.AbstractDialog}
<a name="line39"></a> * @final
<a name="line40"></a> */
<a name="line41"></a>goog.demos.editor.HelloWorldDialog = function(domHelper) {
<a name="line42"></a>  goog.ui.editor.AbstractDialog.call(this, domHelper);
<a name="line43"></a>};
<a name="line44"></a>goog.inherits(goog.demos.editor.HelloWorldDialog,
<a name="line45"></a>              goog.ui.editor.AbstractDialog);
<a name="line46"></a>
<a name="line47"></a>
<a name="line48"></a>// *** Event **************************************************************** //
<a name="line49"></a>
<a name="line50"></a>
<a name="line51"></a>
<a name="line52"></a>/**
<a name="line53"></a> * OK event object for the hello world dialog.
<a name="line54"></a> * @param {string} message Customized hello world message chosen by the user.
<a name="line55"></a> * @constructor
<a name="line56"></a> * @extends {goog.events.Event}
<a name="line57"></a> * @final
<a name="line58"></a> */
<a name="line59"></a>goog.demos.editor.HelloWorldDialog.OkEvent = function(message) {
<a name="line60"></a>  this.message = message;
<a name="line61"></a>};
<a name="line62"></a>goog.inherits(goog.demos.editor.HelloWorldDialog.OkEvent, goog.events.Event);
<a name="line63"></a>
<a name="line64"></a>
<a name="line65"></a>/**
<a name="line66"></a> * Event type.
<a name="line67"></a> * @type {goog.ui.editor.AbstractDialog.EventType}
<a name="line68"></a> * @override
<a name="line69"></a> */
<a name="line70"></a>goog.demos.editor.HelloWorldDialog.OkEvent.prototype.type =
<a name="line71"></a>    goog.ui.editor.AbstractDialog.EventType.OK;
<a name="line72"></a>
<a name="line73"></a>
<a name="line74"></a>/**
<a name="line75"></a> * Customized hello world message chosen by the user.
<a name="line76"></a> * @type {string}
<a name="line77"></a> */
<a name="line78"></a>goog.demos.editor.HelloWorldDialog.OkEvent.prototype.message;
<a name="line79"></a>
<a name="line80"></a>
<a name="line81"></a>// *** Protected interface ************************************************** //
<a name="line82"></a>
<a name="line83"></a>
<a name="line84"></a>/** @override */
<a name="line85"></a>goog.demos.editor.HelloWorldDialog.prototype.createDialogControl = function() {
<a name="line86"></a>  var builder = new goog.ui.editor.AbstractDialog.Builder(this);
<a name="line87"></a>  /** @desc Title of the hello world dialog. */
<a name="line88"></a>  var MSG_HELLO_WORLD_DIALOG_TITLE = goog.getMsg(&#39;Add a Hello World message&#39;);
<a name="line89"></a>  builder.setTitle(MSG_HELLO_WORLD_DIALOG_TITLE).
<a name="line90"></a>      setContent(this.createContent_());
<a name="line91"></a>  return builder.build();
<a name="line92"></a>};
<a name="line93"></a>
<a name="line94"></a>
<a name="line95"></a>/**
<a name="line96"></a> * Creates and returns the event object to be used when dispatching the OK
<a name="line97"></a> * event to listeners, or returns null to prevent the dialog from closing.
<a name="line98"></a> * @param {goog.events.Event} e The event object dispatched by the wrapped
<a name="line99"></a> *     dialog.
<a name="line100"></a> * @return {goog.demos.editor.HelloWorldDialog.OkEvent} The event object to be
<a name="line101"></a> *     used when dispatching the OK event to listeners.
<a name="line102"></a> * @protected
<a name="line103"></a> * @override
<a name="line104"></a> */
<a name="line105"></a>goog.demos.editor.HelloWorldDialog.prototype.createOkEvent = function(e) {
<a name="line106"></a>  var message = this.getMessage_();
<a name="line107"></a>  if (message &amp;&amp;
<a name="line108"></a>      goog.demos.editor.HelloWorldDialog.isValidHelloWorld_(message)) {
<a name="line109"></a>    return new goog.demos.editor.HelloWorldDialog.OkEvent(message);
<a name="line110"></a>  } else {
<a name="line111"></a>    /** @desc Error message telling the user why their message was rejected. */
<a name="line112"></a>    var MSG_HELLO_WORLD_DIALOG_ERROR =
<a name="line113"></a>        goog.getMsg(&#39;Your message must contain the words &quot;hello&quot; and &quot;world&quot;.&#39;);
<a name="line114"></a>    this.dom.getWindow().alert(MSG_HELLO_WORLD_DIALOG_ERROR);
<a name="line115"></a>    return null; // Prevents the dialog from closing.
<a name="line116"></a>  }
<a name="line117"></a>};
<a name="line118"></a>
<a name="line119"></a>
<a name="line120"></a>// *** Private implementation *********************************************** //
<a name="line121"></a>
<a name="line122"></a>
<a name="line123"></a>/**
<a name="line124"></a> * Input element where the user will type their hello world message.
<a name="line125"></a> * @type {Element}
<a name="line126"></a> * @private
<a name="line127"></a> */
<a name="line128"></a>goog.demos.editor.HelloWorldDialog.prototype.input_;
<a name="line129"></a>
<a name="line130"></a>
<a name="line131"></a>/**
<a name="line132"></a> * Creates the DOM structure that makes up the dialog&#39;s content area.
<a name="line133"></a> * @return {Element} The DOM structure that makes up the dialog&#39;s content area.
<a name="line134"></a> * @private
<a name="line135"></a> */
<a name="line136"></a>goog.demos.editor.HelloWorldDialog.prototype.createContent_ = function() {
<a name="line137"></a>  /** @desc Sample hello world message to prepopulate the dialog with. */
<a name="line138"></a>  var MSG_HELLO_WORLD_DIALOG_SAMPLE = goog.getMsg(&#39;Hello, world!&#39;);
<a name="line139"></a>  this.input_ = this.dom.createDom(goog.dom.TagName.INPUT,
<a name="line140"></a>      {size: 25, value: MSG_HELLO_WORLD_DIALOG_SAMPLE});
<a name="line141"></a>  /** @desc Prompt telling the user to enter a hello world message. */
<a name="line142"></a>  var MSG_HELLO_WORLD_DIALOG_PROMPT =
<a name="line143"></a>      goog.getMsg(&#39;Enter your Hello World message&#39;);
<a name="line144"></a>  return this.dom.createDom(goog.dom.TagName.DIV,
<a name="line145"></a>                            null,
<a name="line146"></a>                            [MSG_HELLO_WORLD_DIALOG_PROMPT, this.input_]);
<a name="line147"></a>};
<a name="line148"></a>
<a name="line149"></a>
<a name="line150"></a>/**
<a name="line151"></a> * Returns the hello world message currently typed into the dialog&#39;s input.
<a name="line152"></a> * @return {?string} The hello world message currently typed into the dialog&#39;s
<a name="line153"></a> *     input, or null if called before the input is created.
<a name="line154"></a> * @private
<a name="line155"></a> */
<a name="line156"></a>goog.demos.editor.HelloWorldDialog.prototype.getMessage_ = function() {
<a name="line157"></a>  return this.input_ &amp;&amp; this.input_.value;
<a name="line158"></a>};
<a name="line159"></a>
<a name="line160"></a>
<a name="line161"></a>/**
<a name="line162"></a> * Returns whether or not the given message contains the strings &quot;hello&quot; and
<a name="line163"></a> * &quot;world&quot;. Case-insensitive and order doesn&#39;t matter.
<a name="line164"></a> * @param {string} message The message to be checked.
<a name="line165"></a> * @return {boolean} Whether or not the given message contains the strings
<a name="line166"></a> *     &quot;hello&quot; and &quot;world&quot;.
<a name="line167"></a> * @private
<a name="line168"></a> */
<a name="line169"></a>goog.demos.editor.HelloWorldDialog.isValidHelloWorld_ = function(message) {
<a name="line170"></a>  message = message.toLowerCase();
<a name="line171"></a>  return goog.string.contains(message, &#39;hello&#39;) &amp;&amp;
<a name="line172"></a>         goog.string.contains(message, &#39;world&#39;);
<a name="line173"></a>};
</pre>


</body>
</html>
